package com.jron.cqiu.kernel.util;

import java.io.File;

/**
 * Created by Intellij IDEA.
 *
 * @Author: Yejw
 * @Date: 2008-6-12
 * @Time: 21:58:47
 */
public class SystemProperties {

	/**
	 * Operating Systems Enum
	 */
	public enum OperatingSystem {

		WINDOWS, LINUX, MACOSX, SOLARIS;

		/**
		 * Returns <code>true</code> if Windows Vista is the current operating
		 * system
		 *
		 * @return If Windows Vista is the current operating system
		 */
		public boolean isVista() {
			return (this.equals(OperatingSystem.WINDOWS) && System.getProperty("os.name").toLowerCase().contains("vista"));
		}

	}

	/**
	 * User home dir
	 */
	public static final String userHome = System.getProperty("user.home");

	/**
	 * OS dependent file separator
	 */
	public static final String fileSeparator = System.getProperty("file.separator");

	/**
	 * OS dependent line terminator
	 */
	public static final String lineTerminator = getSystemLineTerminator();

	/**
	 * Operating System
	 */
	public static final OperatingSystem SYSTEM = detectOperatingSystem();

	/**
	 * Detect OS
	 *
	 * @return The detected OS
	 */
	private static OperatingSystem detectOperatingSystem() {
		String osName = System.getProperty("os.name").toLowerCase();
		if (osName.contains("windows")) {
			return OperatingSystem.WINDOWS;
		} else if (osName.contains("mac os x")) {
			return OperatingSystem.MACOSX;
		} else if (osName.contains("sunos")) {
			return OperatingSystem.SOLARIS;
		}
		return OperatingSystem.LINUX;
	}

	private static String getSystemLineTerminator() {
		if (SYSTEM == OperatingSystem.WINDOWS)
			return "\r\n";
		return "\n";
	}

}
